<!-- 岗位树 -->
<template>
	<div id="posttree">
	    <el-tree ref="tree3" :data="data" show-checkbox node-key="id" :default-expanded-keys="[2, 3]"
	      :default-checked-keys="checkdata" :props="defaultProps" :check-strictly="true" @check-change="handleCheckChange">
	    </el-tree>
	  </div>
</template>

<script>
	export default {
	  name: "posttree",
	  props: ['postobj'],
	  data() {
	    return {
	      checkdata: [],
	      data: [{
	        id: 1,
	        label: '辅导师',
	        children: [{
	          id: 4,
	          label: '房地产策划',
	          children: [{
	            id: 9,
	            label: '房地产策划'
	          }, {
	            id: 10,
	            label: '服务人员'
	          }]
	        }]
	      }, {
	        id: 2,
	        label: '飞行器设计',
	        children: [{
	          id: 5,
	          label: 'ebay经'
	        }, {
	          id: 6,
	          label: '2d游戏美术'
	        }]
	      }, {
	        id: 3,
	        label: 'ebay销售',
	      }],
	      defaultProps: {
	        children: 'children',
	        label: 'label'
	      }
	
	    };
	  },
	  methods: {
	    handleCheckChange(data, checked, indeterminate) { //点击树的复选框调用
	      this.postobj(data, checked); //调用属性，调用父组件传过来的函数
	
	      if (checked) {
	        this.checkdata.push(data.id)
	      } else {
	        for (var i = 0; i < this.checkdata.length; i++) {
	          if (this.checkdata[i] == data.id) {
	            this.checkdata.splice(i, 1)
	            break
	          }
	        }
	      }
	    },
	    upcheckdata(value) { //删除树选中(由父组件调用)
	      this.checkdata.splice(this.checkdata.indexOf(value), 1)
	      this.$refs.tree3.setCheckedKeys(this.checkdata);
	
	    }
	  }
	}
</script>

<style>
</style>